from sqlalchemy import Column, ForeignKey, DateTime
from sqlalchemy.dialects.oracle import VARCHAR2, NUMBER
from sqlalchemy.orm import relationship
from app.db.base import Base

from datetime import datetime, timezone



class User(Base):
    __tablename__ = "USERS"
    __table_args__ = {'schema': 'COOP_APP'}
    user_id = Column(VARCHAR2(36), primary_key=True, index=True)
    first_name = Column(VARCHAR2(100), nullable=True)
    last_name = Column(VARCHAR2(100), nullable=True)
    email = Column(VARCHAR2(255), unique=True, nullable=False)
    password_hash = Column(VARCHAR2(255), nullable=False)
    role_id = Column(NUMBER, ForeignKey("COOP_APP.ROLES.role_id"), nullable=True)

    created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
    updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))

    role = relationship("Role", back_populates="users")
    permissions = relationship("UserPermission", back_populates="user")






